<%@page import="java.io.IOException"%>
<%@page import="util.enviaEmail"%>
<%@page import="java.io.PrintWriter"%>
<%@page import="java.io.StringWriter"%>
<%
Connection conn = null;
try {
	conn = new Conexao().getConexao();
} catch (Exception e) {%>
<html>
<head>
	<script type="text/javascript">
		alert("Falha na conexão!!!\n\nVerifique sua conexão com a internet.\n\nE recarregue novamente.");
	</script>
</head>
</html>
<%
	new enviaEmail().enviar(e);
	out.print("falhaConexao");
	return;
}
%>
<%@page import="conexao.Conexao"%>
<%@page import="java.sql.Connection"%>
<%@page import="dao.empresaDao"%>
<%@page import="bean.empresaBean"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%
	Integer sessaoId = (Integer) session.getAttribute("id");
	String sessaoNome = (String) session.getAttribute("nome");
	String sessaoSexo = (String) session.getAttribute("sexo");
	Integer sessaoIdFuncao = (Integer) session.getAttribute("idfuncao");
	Integer sessaoIdEmpresa = (Integer) session.getAttribute("idempresa");
	empresaBean menuEmpresa = new empresaDao().getEmpresa(conn, sessaoIdEmpresa);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<link rel="shortcut icon" href="imagens/date_and_time-icon.gif" type="image/icon" />
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<script src="js/jquery-1.7.2.min.js"></script>
		<script src="js/jquery-ui-1.8.21.custom.min.js"></script>
		<script src="js/ajaxSetup.js"></script>
		<script src="js/jquery.dataTables.min.js"></script>
		<script src="js/jquery.tablesorter.min.js"></script>
		<script src="js/barraProgresso.js"></script>
		<script src="js/jquery.maskMoney.js"></script>
		<script src="js/jquery.maskedinput-1.2.2.js"></script>
		<script src="js/jquery.ui.datepicker-pt-BR.js"></script>
		<script src="js/jquery.combobox.js"></script>
		<link rel="stylesheet" href="css/jquery-ui-1.8.21.custom.css" />
		<link rel="stylesheet" href="css/css.css" />
		<link rel="stylesheet" href="css/jquery.dataTables_themeroller.css" />
		<link rel="stylesheet" href="css/blue/style.css" />
		<title>CG - Controle de Gráfica</title>
		<script>
			$(function() {
				$("#tabelaMenu tr td").mouseover(function() {
					$(this).addClass("ui-state-hover");
				});
				$("#tabelaMenu tbody tr td").mouseout(function() {
					$(this).removeClass("ui-state-hover");
				});	
				
				$("#selectEmpresa").change(function() {
					var idEmpresa = $(this).val();
					$.ajax({
						url:"mudaEmpresa",
						data:{idEmpresa:idEmpresa},
						success:function(html){
							if(html == ""){
								window.location.reload(true);
							}
						}
					});
				});
				
				$("#btnEmpresas").button();
				
			});
			
			function mascara(campo_passado, mascara)
			{
				var campo = campo_passado.value.length;
				var saida = mascara.substring(0,1);
				var texto = mascara.substring(campo);
				if(texto.substring(0,1) != saida)
				{
					campo_passado.value += texto.substring(0,1);
				}
			}
		
			function numero (e)
			{
				navegador = /msie/i.test(navigator.userAgent);
				if(navegador)
					var tecla = event.KeyCode;
				else
					var tecla = e.which;
					
				if(tecla > 47 && tecla <58) //numeros de 0 a 9
					return true;
				else
					{
						if(tecla != 8) //backspace
							return false;
						else
							return true;
					}
			}
		</script>
	</head>
	<body style="margin-left: 0px; margin-right: 0px; margin-top: 0px;">
		<table width="100%" cellspacing="0" cellpadding="0" border="0" id="tableMenu">
			<tr>
				<td>
					<table cellspacing="0" cellpadding="0" border="0" id="tabelaMenu"
						style="margin-bottom: 3px;">
						<tbody>
							<tr>
								<%if (sessaoIdFuncao == 1 || sessaoIdFuncao == 6) {%>
									<td class="menu ui-state-default" onclick="window.location.href='gerenciadorOS.jsp'">Gerenciador_OS</td>
									<td class="menu ui-state-default" onclick="window.location.href='osGeral.jsp'">OS_Geral</td>
									<td class="menu ui-state-default" onclick="window.location.href='relatorio.jsp'">Relatórios</td>
									<td class="menu ui-state-default" onclick="window.location.href='clientes.jsp'">Clientes</td>
									<td class="menu ui-state-default" onclick="window.location.href='usuarios.jsp'">Usuários</td>
									<td class="menu ui-state-default" onclick="window.location.href='empresa.jsp'">Empresa</td>
								<%}
								if (sessaoIdFuncao == 6) {
									List<empresaBean> empresas = new empresaDao().getAll(conn);
								%>
									<th style="padding-left: 10px;">
										<select id="selectEmpresa">
											<%for(int i=0; i<empresas.size(); i++){%>		
												<option <%if(empresas.get(i).getId() == sessaoIdEmpresa){%>
															selected="selected"
														<%}%> 
														<%if(empresas.get(i).getExcluido() == 1){%>
															style="color: red;"
															title="Empresa desativada"
														<%}%>
													value="<%=empresas.get(i).getId()%>"><%=empresas.get(i).getNome()%>
												</option>
											<%}%>
										</select>
									</th>
									<th style="padding-left: 10px;">
										<button id="btnEmpresas" onclick="window.location.href='empresas.jsp'">Clientes</button>
									</th>
								<%}else{%>
									<th style="padding-left: 10px;">
										<%=menuEmpresa.getNome().replaceAll(" ", "_")%>
									</th>
								<%}%>
								<th align="right" width="100%">
									<table style="float: right;" cellspacing="0"
										cellpadding="0" border="0" id="tabelaMenu">
										<tbody>
											<tr>
												<th class="menu" style="cursor: default;"><%=sessaoNome%></th>
												<td class="menu ui-state-default"
													onclick="window.location.href='logoutServlet'">Sair</td>
											</tr>
										</tbody>
									</table>
								</th>
							</tr>
						</tbody>
					</table>
				</td>
			</tr>
		</table>		
		<div id="dialogCarregando">
			<div id='progressbar' style='width: 300px;'></div>
		</div>
	</body>
</html>